/* Copyright 2025 The xLLM Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://github.com/jd-opensource/xllm/blob/main/LICENSE

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#pragma once

#include <torch/torch.h>

#include <functional>

#include "dense_mlp.h"
#include "framework/model/model_args.h"
#include "framework/model/model_input_params.h"
#include "framework/model_context.h"
#include "framework/parallel_state/parallel_args.h"
#include "framework/quant_args.h"
#include "framework/state_dict/state_dict.h"
#include "layers/rms_norm.h"
#include "qwen2_vision_attention.h"

namespace xllm {
namespace layer {

class Qwen2_5_VisionLayerImpl : public torch::nn::Module {
 public:
  explicit Qwen2_5_VisionLayerImpl(const ModelContext& context,
                                   bool is_qwen3_style = false);

  ~Qwen2_5_VisionLayerImpl() {};

  void load_state_dict(const StateDict& state_dict);

  torch::Tensor forward(torch::Tensor& x,
                        torch::Tensor& m_cos_pos,
                        torch::Tensor& m_sin_pos,
                        torch::Tensor& cu_seq_len,
                        std::vector<int32_t>& cu_seq_len_vec,
                        ModelInputParams& input_params,
                        int node_id);

 protected:
  Qwen2VisionAttention attention_{nullptr};
  DenseMLP mlp_{nullptr};
  RmsNorm norm1_{nullptr};
  RmsNorm norm2_{nullptr};
};

class Qwen3_VisionLayerImpl : public Qwen2_5_VisionLayerImpl {
 public:
  Qwen3_VisionLayerImpl(const ModelContext& context);
  void load_state_dict(const StateDict& state_dict);
};

}  // namespace layer
}  // namespace xllm
